
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the AIO3322_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// AIO3322_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
/*#ifdef AIO3322_EXPORTS
#define AIO3322_API __declspec(dllexport)
#else
#define AIO3322_API __declspec(dllimport)
#endif
*/
// This class is exported from the aio3322.dll
/////////////////////////

typedef char            i8;
typedef unsigned char   u8;
typedef short           i16;
typedef unsigned short  u16;
typedef long            i32;
typedef unsigned long   u32;
typedef float           f32;
typedef double          f64;


//////// Error Code ///////////////////////
#define		JSDRV_NO_ERROR			0

/************ Driver Error ***************/
//#define		JSDRV_READ_DATA_ERROR	1
#define		JSDRV_INIT_ERROR		    2		
#define		JSDRV_UNLOCK_ERROR			3	// Driver Error 
#define		JSDRV_LOCK_COUNTER_ERROR	4	// Driver Error 
#define		JSDRV_SET_SECURITY_ERROR	5	// Driver Error 


#define		IRQ_TIMER0					0x0
#define		IRQ_TIMER1					0x1

/************ Device Error ***************/
#define		DEVICE_RW_ERROR			100		
#define		JSDRV_NO_CARD			101		
#define		JSDRV_DUPLICATE_ID		102
#define		JSDRV_PAR_ERROR			104

/************ User Parameter Error ********/
#define		JSAIO_ID_ERROR			300
#define		JSAIO_MODE_ERROR		301
#define		JSAIO_CHANNEL_ERROR		302
#define		JSAIO_CONVERSION_ERROR	305
#define		JSAIO_CONVERSION_BUSY	306

#define		JSAIO_PORT_ERROR    	400
#define		JSAIO_STATE_ERROR	    401
#define		JSAIO_POINT_ERROR	    402
#define		JSAIO_DIR_ERROR			404
#define		JSAIO_EEPROM_RW_ERROR	403
#define		JSAIO_calibration_error	405	

#define		JSAIO_TimerID_error		406
#define		JSAIO_TO_mode_error		407
#define		JSAIO_TI_mode_error		408
#define		JSAIO_PARAMETER_ERROR	409

#define		JSAIO_EVENT_ERROR		500

#ifndef __aio3322_H
  #define __aio3322_H

#ifdef __cplusplus
	extern "C"{
#endif

#define AIO3322Status VOID __declspec(dllexport) APIENTRY //Standard calling convention 
/*************************************************************************************/

AIO3322Status aio3322_initial(void);
AIO3322Status aio3322_close(void);
AIO3322Status aio3322_info(u8 CardID,u16 *address);
AIO3322Status aio3322_get_DeviceHandle(u8 CardID,HANDLE *DeviceHandle);//read device handle


//****** A/D section ******************************************************************

AIO3322Status aio3322_smart_AtoD(u8 CardID,u8 channel,u8 AD_scale,f32 *value);
AIO3322Status aio3322_set_AD_command(u8 CardID,u8 channel,u8 AD_scale);
AIO3322Status aio3322_start_AD_conversion(u8 CardID);
AIO3322Status aio3322_read_AD_status(u8 CardID,u8 *state);
AIO3322Status aio3322_read_AD_data(u8 CardID,i16 *data);


//****** DAQ section ******************************************************************
AIO3322Status aio3322_set_DAQ_sampling_rate(u8 CardID,u8 speed_mode);

//set DAQ mode
AIO3322Status aio3322_set_Digital_trigger_DAQ(u8 CardID,u8 channel,u8 AD_scale);
AIO3322Status aio3322_set_Analog_trigger_DAQ(u8 CardID,u8 channel,u8 AD_scale);
AIO3322Status aio3322_set_Software_trigger_DAQ(u8 CardID,u8 channel,u8 AD_scale);
AIO3322Status aio3322_release_trigger_DAQ(u8 CardID);
AIO3322Status aio3322_read_DAQ_mode(u8 CardID,u8 *mode);

// set retain DAQ counter
AIO3322Status aio3322_set_Trigger_DAQ_retaining_count(u8 CardID,u16 number);

AIO3322Status aio3322_enable_Digital_trigger_DAQ(u8 CardID,u8 enable);
AIO3322Status aio3322_enable_Analog_trigger_DAQ(u8 CardID,u8 enable);
AIO3322Status aio3322_start_Software_trigger_DAQ(u8 CardID,u8 enable);

//set compare event trigger DAQ value and method
AIO3322Status aio3322_config_Analog_Trigger_condition(u8 CardID,u8 AD_scale,u8 method,f32 compare_voltage);

AIO3322Status aio3322_read_DAQ_finish_flag(u8 CardID,u8 *flag);
AIO3322Status aio3322_read_DAQ_cycling_flag(u8 CardID,u8 *flag);
AIO3322Status aio3322_read_DAQ_value(u8 CardID,u16 pointer,f32 *value);
AIO3322Status aio3322_read_DAQ_RAM_data(u8 CardID,u16 pointer,i16 *data);


//****** Digital trigger IN/OUT section ***********************************************
AIO3322Status aio3322_read_Trigger_IN_status(u8 CardID,u8 point,u8 *state);
AIO3322Status aio3322_set_Trigger_IN_polarity(u8 CardID,u8 point,u8 polarity);

AIO3322Status aio3322_config_Trigger_OUT_mode(u8 CardID,u8 point,u8 mode);
AIO3322Status aio3322_write_Trigger_OUT(u8 CardID,u8 point,u8 state);
AIO3322Status aio3322_readback_Trigger_OUT_status(u8 CardID,u8 point,u8 *state);
AIO3322Status aio3322_set_Trigger_OUT_polarity(u8 CardID,u8 point,u8 polarity);

AIO3322Status aio3322_load_Trigger_OUT_pulse_duration(u8 CardID,u32 duration_time);




//****** D/A section ******************************************************************
AIO3322Status aio3322_out_DA_data(u8 CardID,u8 channel,i16 data);




/********************************************************************/
AIO3322Status aio3322_read_port(u8 CardID,u8 port,u8 *data);
AIO3322Status aio3322_read_point(u8 CardID,u8 port,u8 point,u8 *state);
AIO3322Status aio3322_set_port(u8 CardID,u8 data);
AIO3322Status aio3322_set_point(u8 CardID,u8 point,u8 state);



/*******************************************************************************/
AIO3322Status aio3322_set_dedicate_IO(u8 CardID,u8 enable);
AIO3322Status aio3322_readback_dedicate_IO_status(u8 CardID,u8 *enable);
AIO3322Status aio3322_set_timer(u8 CardID,u8 TimerID,u8 To_mode);
AIO3322Status aio3322_set_counter(u8 CardID,u8 TimerID,u8 To_mode,u8 Ti_mode);
AIO3322Status aio3322_set_pwm(u8 CardID,u8 TimerID);
AIO3322Status aio3322_load_GPT(u8 CardID,u8 TimerID,u32 value,u8 preset);
AIO3322Status aio3322_read_GPT(u8 CardID,u8 TimerID,u32 *value,u8 preset);
AIO3322Status aio3322_GPT_enable(u8 CardID,u8 TimerID,u8 enable);
AIO3322Status aio3322_read_parameter(u8 CardID,u8 parameter,u32 *data);
AIO3322Status aio3322_one_shot_command(u8 CardID,u8 TimerID,u32 duration_time);
//AIO3322Status aio3322_set_gate_CNTR(u8 CardID,u8 TimerID,u8 enable);
AIO3322Status aio3322_set_clock_frequency(u8 CardID,u8 freq_mode);



/********************************************************************************/
AIO3322Status aio3322_enable_IRQ(u8 CardID,u8 IRQ_Source,HANDLE *phEvent);
AIO3322Status aio3322_disable_IRQ(u8 CardID,u8 IRQ_Source);
//AIO3322Status aio3322_set_IRQ_mask(u8 CardID,u16 Data);
AIO3322Status aio3322_read_IRQ_status(u8 CardID,u8 IRQ_Source,u8 *status);
AIO3322Status aio3322_link_IRQ_process(u8 CardID,u8 IRQ_Source,void ( __stdcall *callbackAddr)(u8 CardID));
//AIO3322Status aio3322_link_IRQ_process(u8 CardID,u8 IRQ_Source,void ( __cdecl *callbackAddr)(u8 CardID));



/********************************************************************************/

AIO3322Status aio3322_read_security_status(u8 CardID,u8 *lock_status,u8 *seurity_enable);
AIO3322Status aio3322_unlock_security(u8 CardID,u16 password[5]);
AIO3322Status aio3322_set_password(u8 CardID,u16 password[5]);	
AIO3322Status aio3322_change_password(u8 CardID,u16 Oldpassword[5],u16 Password[5]);
AIO3322Status aio3322_clear_password(u8 CardID,u16 Password[5]);	

/**************************************************************************************/

#ifdef __cplusplus
}
#endif

#endif  // belongs to #ifndef __aio3322_H#ifndef __cplusepluse
